<?php
class return_pembeliaan_model extends CI_Model
{
	private $ReturnNo;
    private $KodeSupplier;
    private $KodeBarang;
    private $NoFaktur;
  	private $DateReturn;
	private $Quantity;
	private $Price;
	private $Keterangan;
    private $createdby;
    private $createdon;
    private $lastupdateby;
  	private $lastupdateon;
  	private $active;
	
	function setReturnNo($returnNo){
		$this->ReturnNo = $returnNo;
	}

	function getReturnNo(){
		return $this->ReturnNo;
	}
	
	function setKodeSupplier($kdsupp){
		$this->KodeSupplier = $kdsupp;
	}

	function getKodeSupplier(){
		return $this->KodeSupplier;
	}
	
	function setKodeBarang($kdbrng){
		$this->KodeBarang = $kdbrng;
	}

	function getKodeBarang(){
		return $this->KodeBarang;
	}
	
	function setNoPo($nopo){
		$this->NoPo = $nopo;
	}

	function getNoPo(){
		return $this->NoPo;
	}
	
	function setNoFaktur($nmfktr){
		$this->NoFaktur = $nmfktr;
	}

	function getNoFaktur(){
		return $this->NoFaktur;
	}
	
	function setDateReturn($tgl){
		$this->DateReturn = $tgl;
	}

	function getDateReturn(){
		return $this->DateReturn;
	}
	
	function setQuantity($qty){
		$this->Quantity = $qty;
	}

	function getQuantity(){
		return $this->Quantity;
	}
	
	function setPrice($price){
		$this->Price = $price;
	}

	function getPrice(){
		return $this->Price;
	}
	
	function setKeterangan($ket){
		$this->Keterangan = $ket;
	}

	function getKeterangan(){
		return $this->Keterangan;
	}
	
	function setCreatedBy($c_by){
		$this->createdby = $c_by;
	}

	function getCreatedBy(){
		return $this->createdby;
	}

	function setCreatedOn(){
		$dateNow = date('Y-m-d H:i:s');
		$this->createdon = $dateNow;
	}

	function getCreatedOn(){
		return $this->createdon;
	}

	function setLastUpdateBy($u_by){
		$this->lastupdateby = $u_by;
	}

	function getLastUpdateBy(){
		return $this->lastupdateby;
	}

	function setLastUpdateOn(){
		$dateNow = date('Y-m-d H:i:s');
		$this->lastupdateon = $dateNow;
	}

	function getLastUpdateOn(){
		return $this->lastupdateon;
	}

	function setActive($active_val){
		$this->active = $active_val;
	}

	function getActive(){
		return $this->active;
	}
	
	function __construct(){
		parent::__construct();
	}
	
	function generateReturnNo()
	{
		$query = $this->db->query("select MAX(RIGHT(ReturnNo,4)) as noreturn from return_product_pembelian");
		$kd = "";
		if($query->num_rows()>0)
		{
			foreach($query->result() as $idsupp)
			{
				$tmpsupp = ((int)$idsupp->noreturn)+1;
				$kd = sprintf("%04s", $tmpsupp);
			}
		}
		else
		{
			$kd = "0001";
		}
			
		$kdsuppok="RN".$kd;
		
		return $kdsuppok;
	}
	
	function insertReturnBeli(){
		
		$data = array(
			'ReturnNo' => $this->getReturnNo(),
			'KodeSupplier' => $this->getKodeSupplier(),
			'KodeBarang' => $this->getKodeBarang(),
			'NoPo' => $this->getNoPo(),
			'DateReturn' =>$this->getDateReturn(),
			'Quantity' =>$this->getQuantity(),
			'Price' =>$this->getPrice(),
			'Keterangan' => $this->getKeterangan(),
			'Createdby' => $this->getCreatedBy(),
			'Createdon' => $this->getCreatedOn(),
			'Lastupdateby' => $this->getLastupdateby(),
			'Lastupdateon' => $this->getLastupdateon(),
			'Active' => '1'					
		);
		
		$this->db->insert('return_product_pembelian',$data);
	}
	
	
	
	function getSupplierCode($nopo)
	{
		$this->db->select('KodeSupplier');
		$this->db->where(array('NoPo' => $nopo,'active'=>'1'));
		$query = $this->db->get('order_product');
		return $query->result();
	}
	
}

?>